package com.kunteng.ynhxksh.service;

import com.kunteng.ynhxksh.dao.JYGKDao;
import com.kunteng.ynhxksh.mapper.T_POS_JYXXMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created By ShiYun with IntelliJ IDEA on 2018/4/2 10:45
 *
 * @author: ShiYun
 * @Email: 515867726@qq.com
 * @Date: 2018/4/2
 * To change this template use File | Settings | File Templates.
 */

/**
 * 交易管控服务
 */
@Service
public class JYGKService implements JYGKDao {

    @Autowired
    T_POS_JYXXMapper t_pos_jyxxMapper;
    Logger logger = LoggerFactory.getLogger(JYGKService.class);

    @Override
    public Map getDayJYGK() {
        Map all = new HashMap();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String jysj = format.format(now);
        List<Map> jyjes = t_pos_jyxxMapper.getDayJYJE(jysj);
        Map<String, Integer> area = new HashMap<String, Integer>();
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;
        int five = 0;
        Map dxOne = null;
        Map dxTwo = null;
        Map dxThree = null;
        Map dxFour = null;
        Map dxFive = null;
        for (Map map : jyjes) {
            BigDecimal b = (BigDecimal) map.get("jyje");
            Double d = b.doubleValue();
            if (d > 0.00 && d < 301.00) {
                one++;
                if (dxOne == null)
                    dxOne = map;
            } else if (d >= 301 && d < 1001) {
                two++;
                if (dxTwo == null)
                    dxTwo = map;
            } else if (d >= 1001 && d < 5001) {
                three++;
                if (dxThree == null)
                    dxThree = map;
            } else if (d >= 5001 && d < 10001) {
                four++;
                if (dxFour == null)
                    dxFour = map;
            } else {
                five++;
                if (dxFive == null)
                    dxFive = map;
            }
        }
        area.put("one", one);
        area.put("two", two);
        area.put("three", three);
        area.put("four", four);
        area.put("five", five);

        all.put("area", area);
        if (dxOne != null && dxOne.size() > 0) {
            all.put("dxOne", dxOne);
        }
        if (dxTwo != null && dxTwo.size() > 0) {
            all.put("dxTwo", dxTwo);
        }
        if (dxThree != null && dxThree.size() > 0) {
            all.put("dxThree", dxThree);
        }
        if (dxFour != null && dxFour.size() > 0) {
            all.put("dxFour", dxFour);
        }
        if (dxFive != null && dxFive.size() > 0) {
            all.put("dxFive", dxFive);
        }
        List<Map>list=t_pos_jyxxMapper.getTimeInfo();
        all.put("timeInfo",list);
        return all;
    }

    @Override
    public Map getJeRange() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String jysj = format.format(now);
        List<Map> jyjes = t_pos_jyxxMapper.getDayJYJE(jysj);
        Map<String, Integer> area = new HashMap<String, Integer>();
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;
        int five = 0;
        for (Map map : jyjes) {
            BigDecimal b = (BigDecimal) map.get("jyje");
            Double d = b.doubleValue();
            if (d > 0.00 && d < 301.00) {
                one++;
            } else if (d >= 301 && d < 1001) {
                two++;
            } else if (d >= 1001 && d < 5001) {
                three++;
            } else if (d >= 5001 && d < 10001) {
                four++;
            } else {
                five++;
            }
        }
        area.put("one", one);
        area.put("two", two);
        area.put("three", three);
        area.put("four", four);
        area.put("five", five);
        return area;
    }

    @Override
    public List<Map> getDXInfo() {
        List<Map> all = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String jysj = format.format(now);
        List<Map> jyjes = t_pos_jyxxMapper.getDayJYJE(jysj);
        Map dxOne = null;
        Map dxTwo = null;
        Map dxThree = null;
        Map dxFour = null;
        Map dxFive = null;
        for (Map map : jyjes) {
            BigDecimal b = (BigDecimal) map.get("jyje");
            Double d = b.doubleValue();
            if (d > 0.00 && d < 301.00) {
                if (dxOne == null)
                    dxOne = map;
            } else if (d >= 301 && d < 1001) {
                if (dxTwo == null)
                    dxTwo = map;
            } else if (d >= 1001 && d < 5001) {
                if (dxThree == null)
                    dxThree = map;
            } else if (d >= 5001 && d < 10001) {
                if (dxFour == null)
                    dxFour = map;
            } else {
                if (dxFive == null)
                    dxFive = map;
            }
        }
        if (dxOne != null && dxOne.size() > 0) {
            all.add(dxOne);
        }
        if (dxTwo != null && dxTwo.size() > 0) {
            all.add(dxTwo);
        }
        if (dxThree != null && dxThree.size() > 0) {
            all.add(dxThree);
        }
        if (dxFour != null && dxFour.size() > 0) {
            all.add(dxFour);
        }
        if (dxFive != null && dxFive.size() > 0) {
            all.add(dxFive);
        }
        return all;
    }

    public static void out(Map map) {
        System.out.println("jyje=" + String.valueOf(map.get("jyje")) + " jyxm=" + String.valueOf(map.get("jyxm"))
                + " jysj=" + String.valueOf(map.get("jysj")) + " hymc=" + String.valueOf(map.get("hymc"))
                +" xfmc="+String.valueOf(map.get("xfmc")));
    }

    @Override
    public  List<Map> getTimeInfo() {
//        Map<String,List>infoMap=new HashMap<>();
        List<Map>list=t_pos_jyxxMapper.getTimeInfo();
//        infoMap.put("timeInfo",list);
        return list;
    }
}
